/****************************************************************************
 * Elisa 1.0                                                                *
 *--------------------------------------------------------------------------*
 * Author: Laurent Granvilliers, Vincent Sorin                              *
 * Copyright (c) 2004 Laboratoire d'Informatique de Nantes Atlantique       *
 *--------------------------------------------------------------------------*
 * Elisa is distributed WITHOUT ANY WARRANTY. Read the associated           *
 * COPYRIGHT file for more details.                                         *
 *--------------------------------------------------------------------------*
 * elisa_natural_interval_form.cpp                                          *
 ****************************************************************************/

#include "elisa_natural_interval_form.h"

USING_ELISA


//--------------------------------------------------------------------------
// class NaturalIntervalFormVisitor
//--------------------------------------------------------------------------

void NaturalIntervalFormVisitor::visit(RealExprRep & e)
{
	e.visit(*this);
}

void NaturalIntervalFormVisitor::visited(RealExprRepConst & e)
{
	_node = new NaturalIntervalFormConst(e.getInterval());
}

void NaturalIntervalFormVisitor::visited(RealExprRepIntervalConst & e)
{
	_node = new NaturalIntervalFormConst(e.getInterval());
}

void NaturalIntervalFormVisitor::visited(RealExprRepVar & e)
{
	RealVarImpl *vtemp = dynamic_cast<RealVarImpl *>((e.variable().getImplementation().get()));
	if (vtemp != 0) {
		_node = new NaturalIntervalFormVar(*vtemp);
	}
}

//void
//NaturalIntervalFormVisitor::visited(RealExprRepIntVar& e)
//{
//  RealVarImplementation* vtemp = dynamic_cast<RealVarImplementation*>((e.variable().getImplementation()));
//  if (vtemp != 0)
//  {
//    _node = new NaturalIntervalFormVar(*vtemp);
//  }
//}
//
void NaturalIntervalFormVisitor::visited(RealExprRepAdd & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormAdd(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepMin & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormMin(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepMax & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormMax(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepSum & e)
{
	NaturalIntervalFormSum *sum = new NaturalIntervalFormSum;
	for (int i = 1; i <= e.arity(); ++i) {
		NaturalIntervalFormVisitor v;
		v.visit(*e.const_child(i));
		sum->addChild(v.node());
	}
	_node = sum;
}

void NaturalIntervalFormVisitor::visited(RealExprRepMul & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormMul(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepProd & e)
{
	NaturalIntervalFormProd *prod = new NaturalIntervalFormProd;
	for (int i = 1; i <= e.arity(); ++i) {
		NaturalIntervalFormVisitor v;
		v.visit(*e.const_child(i));
		prod->addChild(v.node());
	}
	_node = prod;
}

void NaturalIntervalFormVisitor::visited(RealExprRepSub & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormSub(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepOpp & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormOpp(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepDiv & e)
{
	NaturalIntervalFormVisitor vl, vr;
	vl.visit(*e.left());
	vr.visit(*e.right());
	_node = new NaturalIntervalFormDiv(vl.node(), vr.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepSqr & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSqr(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepSqrt & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSqrt(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepAbs & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormAbs(v.node());
}


void NaturalIntervalFormVisitor::visited(RealExprRepPow & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormPow(v.node(), e.exponent());
}

void NaturalIntervalFormVisitor::visited(RealExprRepLog & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormLog(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepExp & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormExp(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepCos & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormCos(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepACos & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormACos(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepSin & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSin(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepASin & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSin(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepTan & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormTan(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepATan & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormAtan(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepCosh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormCosh(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepACosh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormACosh(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepSinh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSinh(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepASinh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormSinh(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepTanh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormTanh(v.node());
}

void NaturalIntervalFormVisitor::visited(RealExprRepATanh & e)
{
	NaturalIntervalFormVisitor v;
	v.visit(*e.child());
	_node = new NaturalIntervalFormAtanh(v.node());
}
